//
//  GCMReviceHttpRequst.m
//  GeeCityManager
//
//  Created by 聚城科技 on 16/3/18.
//  Copyright © 2016年 聚城科技. All rights reserved.
//

#import "GCMReviceHttpRequst.h"
#import "GCMReceiveListModel.h"
#import "GCMSLRModel.h"

@implementation GCMReviceHttpRequst


+ (NSURLSessionDataTask *)postFenLeiDataWithURL:(NSString*)url Success:(void (^) (id obj , NSError * err))success{
    NSMutableDictionary *parameters= [[NSMutableDictionary alloc]init];
    
    return [[CZHAppNetAPIClient sharedClient] POST:url parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
        // NSLog(@"接待信息  %@",dict);
        NSArray *ary = [[NSArray alloc]init];
        ary  = [dict valueForKey:@"data"];
         //NSLog(@"接待信息  %@",ary);
        if (success) {
            success(ary,nil);
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        //NSLog(@"++2+  %@",error);
        if (success) {
            success(nil, error);
        }
    }];
    
}

+ (NSURLSessionDataTask *)postReciveListDataWithcourtId:(NSString *)courtId Withremark:(NSString *)remark WithPage:(NSString *)page WithUserName:(NSString *)username Success:(void (^) (id obj , NSError *))success{
    
    NSMutableDictionary *parameters= [[NSMutableDictionary alloc]init];
    
    parameters[@"courtId"] = courtId;
    parameters[@"remark"] = remark;
    parameters[@"page"] = page;
    parameters[@"userName"] = username;
    
    return [[CZHAppNetAPIClient sharedClient] POST:RECEIVELIST_URL parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
        NSLog(@"++1====+  %@",dict);
        NSMutableArray *ReciveListArray = [[NSMutableArray alloc]init];
        NSMutableArray *reciveListArray = [[NSMutableArray alloc]init];
        reciveListArray = [dict objectForKey:@"data"];
        if ([[dict objectForKey:@"data"] isKindOfClass:[NSArray class]]) {
            for (NSDictionary *dict1 in reciveListArray) {
                GCMReceiveListModel *listModel = [[GCMReceiveListModel alloc]initWithDictionary:[CZHChangeNullString getValueFromDictionary:dict1] error:nil];
                listModel.idd = [dict1 valueForKey:@"id"];
                //NSLog(@"%@",listModel);
                [ReciveListArray addObject:listModel];
                //NSLog(@"---%@",ReciveListArray);
            }
            }
            if (success) {
                success(ReciveListArray,nil);
            }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        //NSLog(@"++2+  %@",error);
        if (success) {
            success(nil, error);
        }
    }];
    
}

+ (NSURLSessionDataTask *)postDataWithreceiveId:(NSString *)receiveId Success:(void (^) (id obj , NSError *))success{
    
    NSMutableDictionary *parameters= [[NSMutableDictionary alloc]init];
    
    parameters[@"receiveId"] = receiveId;
    
    return [[CZHAppNetAPIClient sharedClient] POST:RECEIVEDETAIL_URL parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
//        NSLog(@"++1+  %@",dict);
        NSMutableDictionary *noticeListDic = [NSMutableDictionary dictionaryWithDictionary:[CZHChangeNullString getValueFromDictionary:[dict objectForKey:@"data"]]];
        NSLog(@"%@",noticeListDic);
        if (success) {
            success(noticeListDic,nil);
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        //NSLog(@"++2+  %@",error);
        if (success) {
            success(nil, error);
        }
    }];
    
}


+ (NSURLSessionDataTask *)postReciveListDataWithUserName:(NSString *)username WithSearchName:(NSString *)searchname WithPositionId:(NSString *)positionId WithPage:(NSString *)page Success:(void (^) (id obj , NSError *))success{
    
    NSMutableDictionary *parameters= [[NSMutableDictionary alloc]init];
    
    parameters[@"userName"] = username;
    parameters[@"searchName"] = searchname;
    parameters[@"page"] = page;
    parameters[@"positionId"] = positionId;
    
    return [[CZHAppNetAPIClient sharedClient] POST:TASKMEMBER_URL parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
        //NSLog(@"++1+  %@",dict);
        NSMutableArray *ReciveListArray = [[NSMutableArray alloc]init];
        NSMutableArray *reciveListArray = [[NSMutableArray alloc]init];
        reciveListArray = [dict objectForKey:@"data"];
        for (NSDictionary *dict1 in reciveListArray) {
            GCMSLRModel *listModel = [[GCMSLRModel alloc]initWithDictionary:dict1 error:nil];
            listModel.idd = [dict1 valueForKey:@"id"];
            //   NSLog(@"%@",listModel);
            [ReciveListArray addObject:listModel];
            //NSLog(@"---%@",ReciveListArray);
        }
        if (success) {
            success(ReciveListArray,nil);
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        //NSLog(@"++2+  %@",error);
        if (success) {
            success(nil, error);
        }
    }];
    

    
}

@end
